package com.factory.absfactory.pizzastore.order;

import com.factory.absfactory.pizzastore.pizza.Pizza;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @author 薛虎
 * @date 2020/12/24 10:22
 */
public class OrderPizza {

    AbsFactory absFactory;

    //构造器
    public OrderPizza(AbsFactory absFactory) {
        setAbsFactory(absFactory);
    }

    private void setAbsFactory(AbsFactory absFactory) {
        Pizza pizza = null;
        String orderType = ""; //用户输入
        this.absFactory = absFactory;

        do {
            orderType = getType();
            //factory 可能是北京的工厂子类,也可能是伦敦的工厂子类
            pizza = absFactory.createPizza(orderType);
            if (pizza != null) { //订购成功
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            } else {
                System.out.println("订购失败");
                break;
            }
        } while (true);
    }


    //写一个方法,可以获取客户希望订购的披萨种类
    private String getType() {
        try {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza 种类:");
            String str = bufferedReader.readLine();
            return str;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
}
